package jdbc04;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Properties;

/*
* properies使用
* */
public class ProperiesDemo {
    @Test
    public void test01(){
        Properties properties = new Properties();
        properties.put("1","zhangsan");
        properties.put("2","lisi");
        System.out.println(properties);
    }
    @Test
    public void test02(){
        Properties properties = new Properties();
        properties.put("1","zhangsan");
        properties.put("2","lisi");
        System.out.println(properties.getProperty("1"));
    }
    @Test
    public void test03() throws Exception {
        Properties properties = new Properties();
        properties.load(new FileInputStream("src/db.properties"));//在单元测试中 IO流文件的相对路径相对的是当前模块
        System.out.println(properties);
    }
    @Test
    public void test04() throws Exception {
//void load(InputStream inStream)
        Properties properties = new Properties();
        //类加载器中的 getResourceAsStream()方法默认从类的根路径读取文件
        InputStream is =
                ProperiesDemo.class.getClassLoader().getResourceAsStream("db.properties");
        properties.load(is);
        System.out.println(properties);
    }
}
